package com.mhf.controller;

import com.mhf.domain.JSONResult;
import com.mhf.domain.Movie;
import com.mhf.domain.MovieUser;
import com.mhf.domain.OverdueDto;
import com.mhf.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    private UserService userService;
    @GetMapping("/getById/{id}")
    public Movie getById(@PathVariable("id")Long id){
        return userService.getById(id);
    }

    @PostMapping("/buyTickets")
    public JSONResult buyMovieById(@RequestBody MovieUser movieUser){
        try {
            userService.buyMovieById(movieUser);
            return new JSONResult(true,"购票成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new JSONResult(false,"购票失败");
        }
    }

    @GetMapping("/overdue/{id}")
    public OverdueDto overdue(@PathVariable("id")Long id){

        try {
            OverdueDto overdue = userService.overdue(id);
            return overdue;
        } catch (Exception e) {
            e.printStackTrace();
            return new OverdueDto();
        }
    }
}
